package com.yanqu.road.server.cmd.orewar;

import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.orewar.OreWarProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.orewar.CrossOreWarMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


@Cmd(code = Protocol.C_CROSS_OREWAR_USERBASE_SYNC, desc = "用户基本信息更新，涉及到商会冠名的更新")
public class CrossUserBaseInfoSyncCmd extends CrossUnionCommand {

    private long serverId;

    private Map<Long,UserBaseInfo> infoMap = new ConcurrentHashMap<>();

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        OreWarProto.CrossUserBaseInfoSyncMsg reqMsg = OreWarProto.CrossUserBaseInfoSyncMsg.parseFrom(packet.getBytes());
        serverId = reqMsg.getServerId();
        infoMap = new ConcurrentHashMap<>();
        for(OreWarProto.CrossUserBaseInfoTempMsg info : reqMsg.getSyncInfoList()){
            infoMap.put(info.getUserId(),PlayerBasePb.parseBaseUserInfo(info.getPlayerBaseData()));
        }
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossOreWarMgr.baseUserInfoChangeRefresh(infoMap);
    }

    @Override
    public void sendData() {

    }

}
